#!/bin/SH

JAVA_HOME="/home/user/programs/jdks/openjdk17.0.10"
BASE_PATH="/home/www/jphenix"

SERVER_ID=""
PROJECT_NAME=""

JAR_PATH="${BASE_PATH}/${PROJECT_NAME}"
JAR_FILE="${JAR_PATH}/jphenix_boot.jar"

#MEM_ARGS="-XX:PermSize=64m -XX:MaxPermSize=128m -Xms1024M -Xmx1024M"

#DEBUG_MODE="-Xdebug -Xrunjdwp:transport=dt_socket,address=0.0.0.0:28341,server=y,suspend=n"

PID_PATH="${JAR_PATH}/jphenix.pid"
if [ -f ${PID_PATH} ]; then
  PID_VALUE=$(cat ${PID_PATH})
  kill -9 ${PID_VALUE}
fi

while true ; do

if [ -f ${JAR_FILE}.new ]; then
  rm -f ${JAR_FILE}.old
  mv ${JAR_FILE} ${JAR_FILE}.old
  mv ${JAR_FILE}.new ${JAR_FILE}
fi


${JAVA_HOME}/bin/java -jar ${MEM_ARGS} ${DEBUG_MODE} -Djpenginx.prop.path=properties.xml -Djava.awt.headless=true -Djphenix.server.id=${SERVER_ID} ${JAR_FILE} 1 8341 {"ConnTimeOut":300}
RETURN_VALUE=$?
if [ "$RETURN_VALUE" != "9" ] ; then
  exit 9;
fi

done

